import Vec3 from "./vec3";
import Transform from "./transform";
import BroadPhaseProxyCallback from "../broad-phase/broad-phase-proxy-callback";
import RayCastHit from "../shape/ray-cast-hit";
import GjkEpa from "../collision-detector/gjk-epa-detector/gjk-epa";
import CONSTANT from '../constant';

export default class ConvexCastWrapper extends BroadPhaseProxyCallback{
    constructor() {
        super();
        this.rayCastHit = new RayCastHit();
        this.begin = new Transform();
        this.translation = new Vec3();
        this.zero = new Vec3();
        this.callback = null;
        this.convex = null;
    }
    process(proxy) {
        let shape = proxy.userData;
        let type = shape._geom._type;
        if(type < CONSTANT.GEOMETRY_TYPE_SPHERE || type > CONSTANT.GEOMETRY_TYPE_CONVEX_HULL) {
            return;
        }
        if(GjkEpa.instance.convexCast(this.convex,shape._geom,this.begin,shape._transform,this.translation,this.zero,this.rayCastHit)) {
            this.callback.process(shape,this.rayCastHit);
        }
    }
}